package com.xmb.common.service.impl;

import com.xmb.common.dao.XmbUserBonusBlotterMapper;
import com.xmb.common.entity.XmbUserBonusBlotter;
import com.xmb.common.entity.reward.ActivityRanking;
import com.xmb.common.service.UserBonusService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;
import java.util.Optional;

/**
 * Created by lyndon on 2019/4/10.
 */
@Service
public class UserBonusServiceImpl implements UserBonusService{

    @Resource
    private XmbUserBonusBlotterMapper bonusBlotterMapper;

    /**
     * 获取用户的奖金总金额
     * @param uid
     * @return
     */
    public BigDecimal getTotalBonus(Long uid) {
        return Optional.ofNullable(bonusBlotterMapper.getTotalBonus(uid)).orElse(BigDecimal.ZERO);
    }

    /**
     * 保存奖金流水
     * @param record
     * @return
     */
    public int saveBonusBlotter(XmbUserBonusBlotter record) {
        return bonusBlotterMapper.insertSelective(record);
    }

    @Override
    public List<XmbUserBonusBlotter> getBonusList(Long userId, Long typeId, String exchangeType) {
        XmbUserBonusBlotter bonusBlotter = new XmbUserBonusBlotter();
        bonusBlotter.setExchangeType(exchangeType);
        bonusBlotter.setUserId(userId);
        bonusBlotter.setTypeId(typeId);
        return bonusBlotterMapper.getBonusList(bonusBlotter);
    }

    @Override
    public List<ActivityRanking> getBonusRanking(Long typeId) {
        return bonusBlotterMapper.getBonusRanking(typeId);
    }

    @Override
    public ActivityRanking getCurrentUserActivityRewardRanking(Long activityId,Long userId) {
        XmbUserBonusBlotter bonusBlotter = new XmbUserBonusBlotter();
        bonusBlotter.setUserId(userId);
        bonusBlotter.setTypeId(activityId);
        return bonusBlotterMapper.getCurrentUserActivityRewardRanking(bonusBlotter);
    }
}
